﻿using Microsoft.Xna.Framework;
using RoboTrocity;

namespace RoboTrocity {
	class Enemy : Entity {
		public AIModule ai;

		public Enemy(Point _position) :
			base(_position){
			ai = new AIModule(this);
			setStat("speed", 2);
		}

		public override void Update(float timeElapsed) {
			base.Update(timeElapsed);
			ai.Update();
		}

		public void collideWith(Bullet bullet) {
			doDamage(bullet.Damage);
		}

		public override void collideWith(Terrain terrain) {
			Vector2 movement = CollisionHandler.FindMovementOffset(Bounds, terrain.Bounds);

			if (movement.X != 0) {
				if (movement.X > 0) {
					setPositionX(terrain.Bounds.Right + 1);
				} else {
					setPositionX(terrain.Bounds.Left - Width - 1);
				}
				setVelocityX(0);
				ai.CollideWithTerrain();
			}
			if (movement.Y != 0) {
				if (movement.Y > 0) { //colliding with ceiling
					setPositionY(terrain.Bounds.Bottom + 1);
				} else if (movement.Y < 0) {
					setPositionY(terrain.Bounds.Top - Height);
				}
				setVelocityY(0);
			}
		}

		

	}
}
